The invention relates generally to a method and system of optimizing local memory usage in a computer system. More particularly the invention relates to a method and system for enabling a computer to reuse an amount of memory instead of allocating a different portion of the memory.
Common idioms in the JAVA programming language often lead to performance problems when the underlying JAVA code is executed. Such performance problems cause a varying, but often significant performance deficit.
Specifically, source code segments written in an object oriented programming language such as C++ will typically conform to the pattern set forth in TABLE 1.
In contrast, source code segments written in an object oriented programming language, such as JAVA, will typically conform to the example set forth in TABLE 2.
The differences between the two source code segments are subtle in the text, but are rather profound in terms of the underlying executable code. For example, in C++ only one storage copy is associated with xe2x80x9cxxe2x80x9d. This is illustrated in FIG. 2B where it is shown that: when executing xe2x80x9cAnyObject x(create, with, parms)xe2x80x9d in C++, x will be allocated over a single object instance at 78 within memory space 76. On every loop, instead of allocating a new object instance, the function xe2x80x9csome.SourceofNextAnyObject(x)xe2x80x9d reinitializes 78 to new values and reuses the memory space. Thus, the various memory blocks 80 in memory space 76 are never used by the loop and can be used by other processes.
As illustrated in FIG. 2A, however, in JAVA xe2x80x9cxxe2x80x9d is a reference to a series of objects stored in memory space 66. Each time the loop is executed, a new xe2x80x9cinstancexe2x80x9d of x is created. As a result, the xe2x80x9cnewxe2x80x9d operator of the JAVA language instantiates a new object, or creates a new object, by allocating memory for the new object each time xe2x80x9cnewxe2x80x9d is encountered. By way of example, during a first execution of the loop, a memory storage space 68 is allocated for Object 0. Subsequently Object 0 is stored in memory storage space 68. Similarly, memory storage space 70 is allocated for Object 1, which is subsequently stored in that memory storage. This iterative process continues until N new objects have been created and an Nth memory storage space 74 has been allocated for storing Object N. Those of skill in the art will appreciate that the memory storage for each new instantiation of an object need not lie in a contiguous memory space. Instead, the memory storage space(s) may be allocated wherever adequate memory space is located.
In the preceding example, if the loop iterates 20,000,000 times, then the memory space to hold the object is allocated 20,000,000 times. This would amount to a 20,000,000 to one deficit for JAVA to overcome as compared to C++. The number of times that the loop iterates varies in practice. Therefore, the deficit will vary with the iterations and the application of the program.
It will also be appreciated that the processor deficit may not be noticed if the function DoWorkWith executes enough instructions. However, the problem associated with allocating a new memory space each time an object is encountered in an iterative loop is sufficiently pervasive that the function DoWorkWith may have other circumstances that repeat the above illustrated practice. Namely, memory for another object may be allocated on a xe2x80x9conce per loopxe2x80x9d basis within DoWorkWith itself. Regardless of whether a processor deficit is noticed, a storage deficit exists.
Therefore, there is a need for a method and system for optimizing the memory space allocated for each new instance of an object by reusing a previously created memory space (when possible) instead of allocating a new memory space for the object during the execution of a loop.
The present invention relates generally to a method and system for optimizing local memory storage in a computer. More specifically, the present invention relates to reusing local memory storage for each instance of an object that is created within an iterative loop instead of reallocating a new memory space xe2x80x9conce per loop.xe2x80x9d
As noted above, JAVA has a performance deficit compared to other languages (C, C++, RPG, etc.) in that it tends to allocate many short-lived objects on a xe2x80x9conce per loopxe2x80x9d basis rather than a xe2x80x9conce per jobxe2x80x9d basis. The other languages do xe2x80x9conce per jobxe2x80x9d more often. Because there can be a very large number of loop iterations, the cost of creating and garbage collecting all of these objects (many of which only xe2x80x9clivexe2x80x9d for a few JAVA statements or at most, one loop iteration) can be very high. The present invention provides a system and method for optimizing the memory allocation by reducing the allocation cost for that loop from xe2x80x9conce per loopxe2x80x9d to xe2x80x9conce per job.xe2x80x9d
Those skilled in the art will readily understand that a garbage collector in JAVA cleans the dynamic memory when it is needed and there is available time. The garbage collector marks objects throughout the memory space to which there are references and subsequently removes the unmarked ones. Garbage collection is necessary to limit JAVA""s storage costs. If objects are created on a xe2x80x9cper loopxe2x80x9d basis and there are a large number of loop iterations, the main storage cost is unacceptable compared to other languages (e.g., without the garbage collection process). But garbage collection is costly in terms of processor time. Also, since garbage collection runs occasionally, there is a time lag between when any particular object ceases to be in use and when garbage collection next executes. Within this lag or time between collections, storage is wasted. Therefore, while garbage collection keeps the worst case storage deficit far below the example deficit identified above, a substantial storage and processor deficit remains compared to alternative languages.
In accordance with a preferred embodiment, the present invention provides a method of reusing a local memory space in a computer. The method comprises analyzing an incoming stream of computer instructions with an executable module and determining the presence of a first predetermined operator in said stream of computer instructions. If said first predetermined operator is present, the method determines the value of a parameter following said first operator in said stream. If said first predetermined operator is present, the method interposes a second operator in place of said first operator by said executable module and reuses a local memory space to store an instance of said parameter in said memory space in response to the execution of said second operator.
In another embodiment, the present invention provides a method of optimizing the usage of a memory space in a computer while executing a module wherein a new instance of an object is created within each execution of an executable loop. The method comprises reusing said memory space for each new instance of said object created each time said loop is executed whereby said memory space is reclaimed without garbage collecting and is reused without allocating a new memory space.
In still another embodiment, the present invention provides, a computer system. The system comprises a memory configured and arranged to store an object and a processor associated with said memory executing an executable module in said computer having a portion that analyzes an incoming stream of computer instructions.
In yet another embodiment, the present invention provides a program storage device readable by a computer system, it the program storage device tangibly embodying a program of instructions executable by the computer system to perform a method of reusing a local memory space in a computer. The method comprises analyzing an incoming stream of computer instructions with an executable module and determining the presence of a first predetermined operator in said stream of computer instructions. If said first predetermined operator is present, determines the value of a parameter following said first operator in said stream, interposes a second operator in place of said first operator by said executable module and reuses a local memory space to store an instance of said parameter in said memory space in response to the execution of said second operator.
In a further embodiment, the present invention provides a method of transmitting a program product to a computer system. The method comprises: (a) establishing a connection with the computer system; and (b) transmitting the program product being executable by the computer system a method of reusing a local memory space in a computer. The method comprises analyzing an incoming stream of computer instructions with an executable module and determining the presence of a first predetermined operator in said stream of computer instructions. If said first predetermined operator is present, determines the value of a parameter following said first operator in said stream, interposes a second operator in place of said first operator by said executable module and reuses a local memory space to store an instance of said parameter in said memory space in response to the execution of said second operator.
These and various other features as well as advantages of the present invention will become readily apparent to those skilled in the art from the following detailed description and corresponding drawings. As will be realized, the invention is capable of modification without departing from the invention. Accordingly, the drawings and description are to be regarded as being illustrative in nature, and not as restrictive.